<tagLib name="html"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>节点挑选</title>
    <load href="../Public/Css/style.css"/>
    <import file="Js.Util.JTree"/>
    <script language="JavaScript">
        <!--
        function ok() {
            var result = new Array();
            result[0] = new Array();
            result[0][0] = document.getElementById('Name').value;
            result[0][1] = document.getElementById('Id').value;
            result[0][2] = document.getElementById('Level').value;

            returnValue = result;
            window.close();
        }

        //-->
    </script>
    <base target="_self"/>
</head>

<body style="margin:0;overflow:hidden">
<form METHOD="POST" style="margin:0" name="form1" action="">
    <div align="center">
        <table class="order" cellpadding=0 style="margin:0" cellspacing=0 width="100%">
            <tr>
                <td height="5" colspan="2" class="topTd"></td>
            </tr>
            <tr>
                <Th colspan=2 align="center">
                    <div class="fLeft"><input name="nodeCaption" id="nodeCaption" type="text" style="width:165px"></div>
                    <html:imageBtn name="search" value="查询" click="findNode(myTree.treeNodes)"
                                   style="impBtn hMargin fLeft "/>
                </Th>
            </tr>
            <tr>
                <td width="75%">
                    <input type="hidden" id="Id"><input type="hidden" id="Name"><input type="hidden" id="Level">

                    <div id="showTree"></div>
                </td>
            </tr>
            <tr>
                <td colspan=2 align="center">
                    <input type="button" class="button shadow" value="确 定" onclick="ok()">
                    <input type="button" class="button shadow" value="取 消" onclick="window.close()">
                </td>
            </tr>
            <tr>
                <td height="5" colspan="2" class="topTd"></td>
            </tr>
        </table>
    </div>
</form>
<script language="javascript" type="text/javascript">
    <!--
    function setValueById(pObjID, pValue) {
        var obj = document.getElementById(pObjID);
        try {
            obj.value = pValue;
        } catch (e) {
            alert("控件：" + pObjID + "　不存在，或没有value属性")
        }
    }

    function $(pID) {
        return document.getElementById(pID);
    }

    function getNodeAtt(pNode, pAtt) {
        try {
            return pNode.attributes.getNamedItem(pAtt).nodeValue;
        } catch (e) {
            //alert("前台调试错误：\n"+e.message+"\n当前节点不存在: "+pAtt+"这个属性");
        }
    }
    parm = location.href.replace('http://' + location.hostname + '__ACTION__', '');
    var myTree = new JTree("showTree", "__URL__/tree/title/{:urlencode('选择节点')}/caption/title/" + parm, false);
    myTree.setPicPath("__ROOT__/Public/Images/JTreePic/")
    myTree.onclick = function () {
        if (getNodeAtt(myTree.selectNode, "id") == undefined) {
            if (myTree.EXPANDALL == false) {
                myTree.expand(true);
            } else {
                myTree.expand(false);
            }

        } else {
            setValueById("Id", getNodeAtt(myTree.selectNode, "id"));
            setValueById("Name", getNodeAtt(myTree.selectNode, "caption"));
            setValueById("Level", getNodeAtt(myTree.selectNode, "level"));
        }
    }
    myTree.ondblclick = function () {
        if (getNodeAtt(myTree.selectNode, "id") != undefined) {
            setValueById("Id", getNodeAtt(myTree.selectNode, "id"));
            setValueById("Name", getNodeAtt(myTree.selectNode, "caption"));
            setValueById("Level", getNodeAtt(myTree.selectNode, "level"));
            ok();
        }
    }
    myTree.CAPTIONATT = "caption";
    myTree.create();
    myTree.expend(false);

    function vControl(pChoice, pParm) {
        switch (pChoice) {
            case "REPLACE":
                var pattern = /\([0-9]+\)$/;
                return pParm.replace(pattern, "");
                break;
            case "FINDNODE":
                var obj;
                for (var i = 0; obj = pParm[i]; i++) {
                    alert(obj.caption);
                    if (obj.caption == $("nodeCaption").value)
                        obj.click();
                }
                break;
        }
    }

    function findNode(pTree) {
        var obj;
        for (var i = 0; obj = pTree[i]; i++) {
            str = $("nodeCaption").value;
            if (obj.caption.indexOf(str) != '-1') {
                obj.click();
                //obj.parentTreeNode.expand(true)
                myTree.clickItem.parentTreeNode.expand(true);
                return true;
            }
            findNode(obj.treeNodes)
        }
    }

    -->
</script>
</html>
